package pers.zhuli.weblog.utils;

import lombok.Data;

@Data
public class Result {
    private int code;
    private String message;
    private Object payload;

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
        this.payload = "";
    }

    public Result(int code, String message, Object payload) {
        this.message = message;
        this.payload = payload;
        this.code = code;
    }

    public static Result build(ResultCode resultCode, String message) {
        return new Result(resultCode.code, message);
    }

    public static Result build(ResultCode resultCode, String message, Object payload) {
        return new Result(resultCode.code, message, payload);
    }

    public static Result success() {
        return build(ResultCode.GEN_SUCCESS, "success");
    }

    public static Result success(Object payload) {
        return build(ResultCode.GEN_SUCCESS, "success", payload);
    }

    public static Result fail() {
        return build(ResultCode.GEN_FAIL, "fail");
    }
}
